//
//  ContentViewController.m
//  UMDReader
//
//  Created by 张 霄鹤 on 10-1-14.
//  Copyright 2010 xhzhang. All rights reserved.
//

#import "ContentViewController.h"


@implementation ContentViewController

@synthesize content;
@synthesize tl;
@synthesize currentChapter;
@synthesize ebch;

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)viewDidAppear:(BOOL)animated{
	[super viewDidAppear:animated];
	//[textView setText:self.content];
	//self.navigationItem.title = self.tl;
	//[textView scrollRangeToVisible:NSMakeRange(0, 1)];
	if(currentChapter){
		[textView setText:currentChapter.content];
		self.navigationItem.title = currentChapter.title;
		// [textView scrollRangeToVisible:NSMakeRange(currentChapter.readloc, 1)];
		[textView scrollRangeToVisible:NSMakeRange(0, 1)];
	}else if(ebch){
		[textView setText:[ebch getContent]];
		self.navigationItem.title = ebch.title;
		// [textView scrollRangeToVisible:NSMakeRange(currentChapter.readloc, 1)];
		[textView scrollRangeToVisible:NSMakeRange(0, 1)];
	}
}

- (void)viewDidDisappear:(BOOL)animated{
	[super viewDidDisappear:animated];
	[textView setText:@""];
	self.content = @"";
	self.tl = @"";
	// NSInteger cx = textView.contentOffset.x;
	// NSLog(@"cx = %d",cx);
	// currentChapter.readloc = cx;
}



/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}

- (void)setContent:(NSString *)c withTitle:(NSString *)t{
	self.content = c;
	self.tl = t;
}

- (void)setChapter:(Chapter *)ch{
	self.currentChapter = ch;
}

- (void)setEBChapter:(EBChapter *)ec{
	self.ebch = ec;
}


- (void)dealloc {
	[content release];
	[tl release];
    [super dealloc];
}


@end
